home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / BTSETVBU.C < prev    next >
Text File  |  1991-09-23  |  3KB  |  97 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btsetvbu.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STDDEF
  11. #include <stddef.h>
  12. #endif
  13.  
  14. /* library headers */
  15. #include <blkio.h>
  16.  
  17. /* local headers */
  18. #include "btree_.h"
  19.  
  20. /*man---------------------------------------------------------------------------
  21. NAME
  22.      btsetvbuf - assign buffering to a btree
  23.  
  24. SYNOPSIS
  25.      #include <btree.h>
  26.  
  27.      int btsetvbuf(btp, buf, bufcnt)
  28.      btree_t *btp;
  29.      void *buf;
  30.      size_t bufcnt;
  31.  
  32. DESCRIPTION
  33.      The btsetvbuf function is used to assign buffering to a btree.
  34.      bufcnt specifies the number of btree nodes to be buffered.  If
  35.      bufcnt has a value of zero, the btree will be completely
  36.      unbuffered.  If buf is not the NULL pointer, the storage area it
  37.      points to will be used instead of one automatically allocated for
  38.      buffering.
  39.  
  40.      The size of the storage area needed can be obtained using the
  41.      BTBUFSIZE() macro:
  42.  
  43.           char buf[BTBUFSIZE(M, KEYSIZE, BUFCNT)];
  44.           btsetvbuf(btp, buf, BUFCNT);
  45.  
  46.      where M is the degree of the btree, KEYSIZE is the size of the
  47.      keys int the btree, and BUFCNT is the number of nodes to buffer.
  48.  
  49.      Any previously buffered data is flushed before installing the new
  50.      buffer area, so btsetvbuf may be called more than once.  This
  51.      allows the buffer size to be varied with the file size.
  52.  
  53.      btsetvbuf will fail if one or more of the following is true:
  54.  
  55.      [EINVAL]       btp is not a valid btree.
  56.      [ENOMEM]       Not enough memory is available for the calling
  57.                     process to allocate.
  58.      [BTENOPEN]     btp is not open.
  59.  
  60. SEE ALSO
  61.      btsetbuf, btsync.
  62.  
  63. DIAGNOSTICS
  64.      Upon successful completion, a value of 0 is returned.  Otherwise,
  65.      a value of -1 is returned, and errno set to indicate the error.
  66.  
  67. ------------------------------------------------------------------------------*/
  68. #ifdef AC_PROTO
  69. int btsetvbuf(btree_t *btp, void *buf, size_t bufcnt)
  70. #else
  71. int btsetvbuf(btp, buf, bufcnt)
  72. btree_t *btp;
  73. void *buf;
  74. size_t bufcnt;
  75. #endif
  76. {
  77.     /* validate arguments */
  78.     if (!bt_valid(btp)) {
  79.         errno = EINVAL;
  80.         return -1;
  81.     }
  82.  
  83.     /* check if not open */
  84.     if (!(btp->flags & BTOPEN)) {
  85.         errno = BTENOPEN;
  86.         return -1;
  87.     }
  88.  
  89.     /* set buffering */
  90.     if (bsetvbuf(btp->bp, buf, bt_blksize(btp), bufcnt) == -1) {
  91.         BTEPRINT;
  92.         return -1;
  93.     }
  94.  
  95.     return 0;
  96. }
  97.